# Vendor2协议API测试脚本 (PowerShell)

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "Vendor2协议API测试" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

# 服务器地址
$SERVER = "http://localhost:8000"

# 设备IMEI
$IMEI = "869778076234039"

Write-Host "📡 服务器地址: $SERVER" -ForegroundColor Green
Write-Host "📱 设备IMEI: $IMEI" -ForegroundColor Green
Write-Host ""

# ========== 测试1: 发送WiFi修改指令 ==========
Write-Host "🔍 测试1: 发送WiFi修改指令" -ForegroundColor Yellow
Write-Host "----------------------------------------" -ForegroundColor Yellow

$body1 = @{
    mac = $IMEI
    type = 1
    vendor = "vendor2"
    params = @{
        hotspot_name = "TestWiFi"
        hotspot_password = "password123"
        hotspot_whether_hide = 0
        status = 1
    }
} | ConvertTo-Json

Invoke-WebRequest -Uri "$SERVER/api/device/command/send" `
    -Method POST `
    -ContentType "application/json" `
    -Body $body1 | Select-Object -ExpandProperty Content | ConvertFrom-Json | ConvertTo-Json -Depth 10

Write-Host ""
Write-Host ""

# ========== 测试2: 发送设备重启指令 ==========
Write-Host "🔍 测试2: 发送设备重启指令" -ForegroundColor Yellow
Write-Host "----------------------------------------" -ForegroundColor Yellow

$body2 = @{
    mac = $IMEI
    type = 3
    vendor = "vendor2"
    params = @{}
} | ConvertTo-Json

Invoke-WebRequest -Uri "$SERVER/api/device/command/send" `
    -Method POST `
    -ContentType "application/json" `
    -Body $body2 | Select-Object -ExpandProperty Content | ConvertFrom-Json | ConvertTo-Json -Depth 10

Write-Host ""
Write-Host ""

# ========== 测试3: 发送上报间隔设置 ==========
Write-Host "🔍 测试3: 发送上报间隔设置" -ForegroundColor Yellow
Write-Host "----------------------------------------" -ForegroundColor Yellow

$body3 = @{
    mac = $IMEI
    type = 8
    vendor = "vendor2"
    params = @{
        nextRptTime = 300000
    }
} | ConvertTo-Json

Invoke-WebRequest -Uri "$SERVER/api/device/command/send" `
    -Method POST `
    -ContentType "application/json" `
    -Body $body3 | Select-Object -ExpandProperty Content | ConvertFrom-Json | ConvertTo-Json -Depth 10

Write-Host ""
Write-Host ""

# ========== 测试4: 发送固件下载指令 ==========
Write-Host "🔍 测试4: 发送固件下载指令" -ForegroundColor Yellow
Write-Host "----------------------------------------" -ForegroundColor Yellow

$body4 = @{
    mac = $IMEI
    type = 9
    vendor = "vendor2"
    params = @{
        firmware_url = "http://example.com/firmware.bin"
    }
} | ConvertTo-Json

Invoke-WebRequest -Uri "$SERVER/api/device/command/send" `
    -Method POST `
    -ContentType "application/json" `
    -Body $body4 | Select-Object -ExpandProperty Content | ConvertFrom-Json | ConvertTo-Json -Depth 10

Write-Host ""
Write-Host ""

Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "✅ 所有测试完成" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan

